package pierwszy.testNGexcercises;

import java.lang.reflect.Method;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;

import ch.qos.logback.classic.Level;

import static org.assertj.core.api.Assertions.assertThat;
//import ch.qos.logback.classic.Logger;



@Test (groups = "mainGroup")
public class TestNGexercises1 {
		
	Logger logger = LoggerFactory.getLogger(TestNGexercises1.class);
	
	ch.qos.logback.classic.Logger lgr = 
	        (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.foo");

	
	@BeforeSuite (alwaysRun = true)
	void bS(){
		lgr.info("Effective level is: {} and level is: {}", lgr.getEffectiveLevel(), lgr.getLevel());
		lgr.setLevel(Level.TRACE);
		lgr.info("Effective level is: {} and level is: {}", lgr.getEffectiveLevel(), lgr.getLevel());
		logger.info("Is trace enabled: {}", String.valueOf(logger.isTraceEnabled()));
		logger.info("Is debug enabled: {}", String.valueOf(logger.isDebugEnabled()));
		logger.info("Is info enabled: {}", String.valueOf(logger.isInfoEnabled()));
		logger.info("Is warn enabled: {}", String.valueOf(logger.isWarnEnabled()));
		logger.info("Is error enabled: {}", String.valueOf(logger.isErrorEnabled()));

		logger.trace("Before suite.");
		logger.debug("Before suite.");
		logger.info("Before suite.");
		logger.warn("Before suite.");
		logger.error("Before suite.");
	}
	
	@AfterSuite (alwaysRun = true)
	public void aS(){
		System.out.println("After suite.");
		logger.info("After suite.");
		//assertThat(logger).
	}
	
	@BeforeTest(alwaysRun = true)
	public void bT(){
		System.out.println("Before test.");
		logger.info("Before test.");
	}
	
	@AfterTest (alwaysRun = true)
	public void aT(){
		System.out.println("After test.");
		logger.trace("After test.");
	}
	
	@BeforeGroups (alwaysRun = true)
	public void bG(){
		System.out.println("Before groups.");
		logger.warn("Before groups.");
	}
	
	@AfterGroups (alwaysRun = true)
	public void aG(){
		System.out.println("After groups.");
	}
	
	@BeforeClass (alwaysRun = true)
	public void bC(){
		System.out.println("Before class.");
	}
	
	@AfterClass (alwaysRun = true)
	public void aC(){
		System.out.println("After class.");
	}
	
	@BeforeMethod (alwaysRun = true)
	public void bM(Method m){
		System.out.println("Before method." + m.getName());
	}
	
	@AfterMethod (alwaysRun = true)
	public void aM(Method m){
		System.out.println("After method." +  m.getName());
	}
	
	
	@DataProvider (name = "dataProvider")
	public Object[][] dp(){
		return new Object[][]{
				{"TEST dp1"},
				{"TEST dp2"}
		};
	}
	
	@Test(groups = "groupC", dataProvider="dataProvider")
	public void TEST1(String dp){
		System.out.println("TEST 1. " + dp);
	}
	
	@Test (groups = "groupD")
	public void TEST2(){
		System.out.println("TEST 2.");
	}
	
	@Test (groups = "groupC")
	public void TEST3(){
		System.out.println("TEST 3.");
	}
	
	@Test(groups = "groupE")
	public void TEST4(){
		System.out.println("TEST 4. ");
	}
	
	@Test (groups = "groupD")
	public void TEST5(){
		System.out.println("TEST 5.");
	}
	
	@Test (groups = "groupC")
	public void TEST6(){
		System.out.println("TEST 6.");
	}
	
	

}
